package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusDeviceWeather;
import com.ruoyi.business.service.IBusDeviceWeatherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 天气Controller
 * 
 * @author ruoyi
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/device/weather")
@Api(tags = "设施农业-天气")
public class BusDeviceWeatherController extends BaseController
{
    @Autowired
    private IBusDeviceWeatherService busDeviceWeatherService;

    /**
     * 查询天气列表
     */
    @GetMapping("/list")
    @ApiOperation("列表 ")
    public TableDataInfo list(BusDeviceWeather busDeviceWeather)
    {
        startPage();
        List<BusDeviceWeather> list = busDeviceWeatherService.selectBusDeviceWeatherList(busDeviceWeather);
        return getDataTable(list);
    }

    /**
     * 导出天气列表
     */
    @PreAuthorize("@ss.hasPermi('device:weather:export')")
    @Log(title = "天气", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusDeviceWeather busDeviceWeather)
    {
        List<BusDeviceWeather> list = busDeviceWeatherService.selectBusDeviceWeatherList(busDeviceWeather);
        ExcelUtil<BusDeviceWeather> util = new ExcelUtil<BusDeviceWeather>(BusDeviceWeather.class);
        util.exportExcel(response, list, "天气数据");
    }

    /**
     * 获取天气详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:weather:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busDeviceWeatherService.selectBusDeviceWeatherById(id));
    }

    /**
     * 新增天气
     */
    @PreAuthorize("@ss.hasPermi('device:weather:add')")
    @Log(title = "天气", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusDeviceWeather busDeviceWeather)
    {
        return toAjax(busDeviceWeatherService.insertBusDeviceWeather(busDeviceWeather));
    }

    /**
     * 修改天气
     */
    @PreAuthorize("@ss.hasPermi('device:weather:edit')")
    @Log(title = "天气", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusDeviceWeather busDeviceWeather)
    {
        return toAjax(busDeviceWeatherService.updateBusDeviceWeather(busDeviceWeather));
    }

    /**
     * 删除天气
     */
    @PreAuthorize("@ss.hasPermi('device:weather:remove')")
    @Log(title = "天气", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busDeviceWeatherService.deleteBusDeviceWeatherByIds(ids));
    }
}
